<?php

	/**
	 * File : header_bar_button.php
	 * Description : Définition et fonctions du bouton de la barre d'en-tête
	 * Date : 07.08.2012 15:00:05
	 * 
	 * This file is part of Phenix.  Phenix is free software: you can
	 * redistribute it and/or modify it under the terms of the GNU General Public
	 * License as published by the Free Software Foundation, version 2.
	 *
	 * This program is distributed in the hope that it will be useful, but WITHOUT
	 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
	 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
	 * details.
	 *
	 * You should have received a copy of the GNU General Public License along with
	 * this program; if not, write to the Free Software Foundation, Inc., 51
	 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
	 *
	 * Nils Schaetti <n.schaetti@gmail.com>
	**/

	/*
	 * Type de boutons
	 */
	define('BUTTON_TYPE_TEXT','text');
	define('BUTTON_TYPE_IMAGE','image');
	
	/*
	 * Propriété non définie
	 */
	define('NOT_DEFINED','');
	
	/*
	 * Position du bouton
	 */
	define('BUTTON_POSITION_LEFT','left');
	define('BUTTON_POSITION_RIGHT','right');

	// Cette classe représente un bouton de la barre d'en-tête
	class ktkHeaderBarButton
	{
	
		/*
		 * Propriétés
		 */
		 
		// Couleur du texte
		private $Foreground;
	
		// Position
		private $Position;
	
		// Type
		private $Type;
		
		// Texte
		private $Text;
		
		// Image
		private $Image;
		
		// Hauteur
		private $Height;
		
		// Lien
		private $Link;
		
		// Font size
		private $FontSize = 11.5;
		
		// Padding-top
		private $PaddingTop = NOT_DEFINED;
		
		// Taile de l'image
		private $ImageHeight = NOT_DEFINED;
		
		// Nom du bouton
		private $Name;
	
		/*
		 * Constructeur
		 */
		function ktkHeaderBarButton($Name, $Foreground = NOT_DEFINED, $Position = NOT_DEFINED, $Type = NOT_DEFINED, $param = NOT_DEFINED, $Link = NOT_DEFINED, $FontSize = NOT_DEFINED)
		{
			$this->Name = $Name;
			// Propriétés
			$this->Foreground = $Foreground;
			$this->Position = $Position;
			$this->Type = $Type;
			if($Type == BUTTON_TYPE_TEXT)
				$this->Text = $param;
			else
				$this->Image = $param;
			if($Link != NOT_DEFINED)
				$this->Link = $Link;

			if($Type === BUTTON_TYPE_TEXT)
			{
				if($FontSize != NOT_DEFINED)
				{
					$this->FontSize = $FontSize;
				}
			}
			else
			{
				if($FontSize != NOT_DEFINED)
				{
					$this->ImageHeight = $FontSize;
				}
			}
		}
		
		/*
		 * Renvoi le code
		 */
		function getCode()
		{
			// Style CSS
			$style = '';
			$style2 = '';
		
			// Code HTML
			$code = <<< __DELIMITER__
			<!-- Bouton -->		
			<div class="ktkHeaderButton" id="{$this->Name}" style="@@_STYLE_@@">
				<a href="@@_LINK_@@" style="@@_STYLE2_@@">@@_BUTTON_@@</a>
			</div>
__DELIMITER__;

			// Couleur du texte
			if($this->Foreground !== NOT_DEFINED)
				$style2 .= 'color: '.$this->Foreground.';';
				
			// Position
			if($this->Position !== NOT_DEFINED)
				$style .= 'float: '.$this->Position.';';
				
			// Padding top
			if($this->PaddingTop != NOT_DEFINED)
				$style .= 'padding-top: '.$this->PaddingTop.'px;';

			// Selon le type
			if($this->Type === BUTTON_TYPE_TEXT)
				$code = str_replace('@@_BUTTON_@@', $this->Text, $code);
			else
				$code = str_replace('@@_BUTTON_@@', '<img src="'.$this->Image.'">', $code);
				
			// Espacement selon type
			if($this->Type == BUTTON_TYPE_TEXT)
			{
				$style .= 'margin-left: 12px;';
			}

			// Style
			$code = str_replace('@@_STYLE_@@', $style, $code);
			$code = str_replace('@@_STYLE2_@@', $style2, $code);
			
			// Lien
			$code = str_replace('@@_LINK_@@', $this->Link, $code);
				
			// Return code
			return $code;
		}
		
		/*
		 * Change le padding du haut
		 */
		function setPaddingTop($padding_top)
		{
			$this->PaddingTop = $padding_top;
		}
		
		/*
		 * Change la hauteur
		 */
		function setHeight($height)
		{
			$this->Height = $height;
		}
		
		/*
		 * Retourne la hauteur
		 */
		function getHeight()
		{
			return $this->Height;
		}
		
		/*
		 * Change la hauteur de texte
		 */
		function setFontSize($height)
		{
			$this->FontSize = $height;
		}
		
		/*
		 * Retourne la hauteur de texte
		 */
		function getFontSize()
		{
			return $this->FontSize;
		}
		
		/*
		 * Change le type
		 */
		function setTyoe($Type)
		{
			$this->Type = $Type;
		}
		
		/*
		 * Retourne le type
		 */
		function getType()
		{
			return $this->Type;
		}
		
		/*
		 * Change la hauteur de l'image
		 */
		function setImageHeight($height)
		{
			$this->ImageHeight = $height;
		}
		
		/*
		 * Retourne la hauteur de l'image
		 */
		function getImageHeight()
		{
			return $this->ImageHeight;
		}
	
	}

?>
